/**
* Created by yyr
* 基金储备库-管理机构信息
*/
<template>
    <div class="ca-p-20 ca-box">
        <div v-if="!showEdit">
            <div class="ca-title">
                <h3>管理机构信息</h3>
                <el-button type="text" class="ca-edit-btn el-icon-edit ca-right" :disabled="!isAuthBasicEdit" @click="showEdit=true">编辑</el-button>
            </div>
            <el-form label-width="180px" :model="fundMechanism">
                <el-row>
                    <el-col :span="11">
                        <el-form-item label="机构名称：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.mechanismName}}
                        </el-form-item>
                        <el-form-item label="执行事务合伙人：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.partner}}
                        </el-form-item>
                        <el-form-item label="成立时间：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break">
                            {{fundMechanism.foundingTime}}
                        </el-form-item>
                        <el-form-item label="认缴金额（万元）：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break">
                            {{fundMechanism.subscribed}}
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="法定代表人：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.representative}}
                        </el-form-item>
                        <el-form-item label="注册地址：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break">
                            {{address}}
                        </el-form-item>
                        <el-form-item label="注册资本（万元）：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break">
                            {{fundMechanism.register}}
                        </el-form-item>
                        <el-form-item label="实缴金额（万元）：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break">
                            {{fundMechanism.receipts}}
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span='22'>
                        <el-form-item label="股东出资金额和比例：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.proportion}}
                        </el-form-item>
                        <el-form-item label="公司治理：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.govern}}
                        </el-form-item>
                        <el-form-item label="内控机制：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.mechanism}}
                        </el-form-item>
                        <el-form-item label="管理制度：" class="el-form-item-m-b-0 el-form-item__content-font-12 el-break wordWrap">
                            {{fundMechanism.rule}}
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <csManagementAgency
            v-else
            @close="showEdit = false"
            :fundMechanism="fundMechanism"
            @saveManageOrg="saveManageOrg"
            @changeRegion="changeRegion"
        ></csManagementAgency>
    </div>
</template>
<script type="text/ecmascript-6">
     import {api} from '../api';
     import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
     import {isNoAuth} from '__service/utils';
    export default {
        data() {
            return {
                isAuthBasicEdit: isNoAuth('已投资基金-基金详情-编辑'),
                showEdit: false,
                itemId: this.$route.params.fundId,
                fundMechanism: {
                    foundingTime: '', //成立时间
                    fundId: '', //基金id
                    govern: '', //公司治理
                    id: '', //主id
                    mechanism: '', //内控机制
                    mechanismName: '', //机构名称
                    partner: '', //执行事务合伙人
                    proportion: 0, //股东出资金额和比例
                    receipts: 0, //实收资本
                    region: [ //注册地址
                        {
                            businessId: '',
                            businessType: 0,
                            city: '',
                            district: '',
                            id: '',
                            province: '',
                            registrationDetailed: ''
                        }
                    ],
                    register: 0, //注册资本
                    representative: '', //法定代表人
                    rule: '', //管理制度
                    subscribed: 0 //认缴金额
                },
                address: '',
            }
        },
        created() {
            this.getManageDetail();
        },
        props: {

        },
        watch: {
        },
        methods: {
            getManageDetail() {
                apiHttp(api.MANAGE_ORG,{fundId: this.itemId}).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundMechanism = ret.data;
                        this.fundMechanism.foundingTime = this.fundMechanism.foundingTime ? this.$moment(this.fundMechanism.foundingTime).format('YYYY-MM-DD') : '';
                        if (this.fundMechanism.region && this.fundMechanism.region.length > 0 ) {
                            this.address = this.fundMechanism.region[0].registrationDetailed;
                        }
                    }
                })
            },
            saveManageOrg(fundMechanism) {
                apiHttp(api.MANAGE_ORG_CHANGE,fundMechanism).then( ret=>{
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            type: 'success',
                            message: '修改成功!',
                            center: true
                        });
                        this.getManageDetail();
                        this.$emit('addRedDot',0)
                        this.showEdit = false;
                    }
                })
            },
            // 改变注册地点
            changeRegion(val) {
                this.fundMechanism.region = [];
                this.fundMechanism.region.push({
                    businessId: this.itemId,
                    businessType: val.businessType,
                    city: val.city,               // 市
                    district: val.district,       // 区
                    id: '',                       // id
                    province: val.province,       // 省
                    registrationDetailed: val.registrationDetailed,  // 详细地址
                })
            },
        },
        components: {
            'csManagementAgency': require('./edit'),//管理机构信息edit页
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.ca-right {
    float: right;
}
.wordWrap{
    word-break: break-all;
}
</style>
